package com.seu.project.seuquiz.model.req;

import com.seu.project.seuquiz.common.PageRequest;
import com.seu.project.seuquiz.model.dto.userQuestionMap.UserQuestionMapQueryRequest;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author SoftPto
 * @createDate: 2023-08-12 16:39
 */
@Data
@Builder
@Slf4j
@NoArgsConstructor
@AllArgsConstructor
public class UserQuestionReq extends PageRequest implements Serializable {

    /**
     * 学号
     */
    private String studentId;

    /**
     * 题目id
     */
    private Long questionId;

    /**
     * 题目类型（单选/多选/判断/简答等）
     */
    private String questionType;

    /**
     * 类型（比如党史）
     */
    private String type;

    public static UserQuestionMapQueryRequest toQueryRequest(UserQuestionReq req, Set<Long> questionIds) {
        List<String> collect = questionIds.stream().map(Objects::toString).collect(Collectors.toList());
        return UserQuestionMapQueryRequest.builder()
                .studentId(req.studentId)
                .questionId(req.questionId == null ? null : String.valueOf(req.questionId))
                .questionIds(collect)
                .build();
    }
}
